#include <iostream>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
using namespace std;

void printpending(sigset_t& pending) {
    for (int signo = 31; signo >= 1; signo--) {
        cout << (sigismember(&pending, signo) ? "1" : "0");
    }
    cout << endl;
    sleep(1);
}
int main() {
    cout << getpid() << endl;
    sigset_t bst, oldset;   //栈区
    sigemptyset(&bst);
    sigaddset(&bst, 2);    //此时并没有设置到进程的task_struct中

    sigprocmask(SIG_SETMASK, &bst, &oldset);    //此时已完成屏蔽

    sigset_t pending;
    int cnt = 10;
    while (cnt--) {
        int n = sigpending(&pending);
        if (n < 0) continue;

        printpending(pending);
        if (cnt == 0) {
            sigprocmask(SIG_SETMASK, &oldset, nullptr);    
        }
    }
} 